/**
 * 
 */
package org.metaverse.h2.sql;

import java.io.IOException;

import org.singularity.io.StringUtil;

/**
 * @author vjache
 *
 */
public class SQL {

	private String _ddl;
	private String _dmeInsert;
	private String _senaryInsert;
	private String _senaryDelete;
	private String _valueInsert;
	private String _idsByValues;
	private String _valueById;
	private String _clean;

	/**
	 * @throws Exception 
	 * 
	 */
	public SQL(String aSchemaName) throws Exception {
		_ddl = extract(aSchemaName, "warehouse-scheme.sql");
		_clean = extract(aSchemaName, "warehouse-clean.sql");
		_dmeInsert = extract(aSchemaName, "dme-insert.sql");
		_senaryInsert = extract(aSchemaName, "senary-insert.sql");
		_senaryDelete = extract(aSchemaName, "senary-delete.sql");
		_valueInsert = extract(aSchemaName, "value-insert.sql");
		_idsByValues = extract(aSchemaName, "get-id-by-value.sql");
		_valueById = extract(aSchemaName, "get-value-by-id.sql");
	}

	private static String extract(String aSchema, final String name)
			throws IOException {
		return StringUtil.readFullyUTF8(SQL.class.getResourceAsStream(name)).replace("${Schema}", aSchema);
	}

	/**
	 * @return the ddl
	 */
	public final String getDDL() 
	{return _ddl;}

	/**
	 * @return the dmeInsert
	 */
	public final String getDMEInsert() 
	{return _dmeInsert;}
	
	/**
	 * @return the dmeInsert
	 */
	public final String getSenaryInsert() 
	{return _senaryInsert;}
	public final String getSenaryDelete() 
	{return _senaryDelete;}

	/**
	 * @return the valueInsert
	 */
	public final String getValueInsert() 
	{return _valueInsert;}

	public final String getIdByValue() 
	{return _idsByValues;}

	public String getValueById() 
	{return _valueById;}

	public String getWarehouseClean() 
	{return _clean;}
}
